<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生产产品" prop="productId">
        <el-select v-model="queryParams.productId" placeholder="请选择产品" @keyup.enter.native="handleQuery">
          <el-option :label="item.productName" :value="item.productId" :key="item.productId" v-for="item in productList"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="List">
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="订单数量" align="center" prop="orderCount" />
      <el-table-column label="订单入库数量" align="center" prop="orderStoreCount" />
      <el-table-column label="订单折损率" align="center" prop="orderLoss" :formatter="showOrderLossPercent"/>
      <el-table-column label="生产数量" align="center" prop="produceCount" />
      <el-table-column label="生产折损率" align="center" prop="produceLoss" :formatter="showProduceLossPercent"/>
      <el-table-column label="销售数量" align="center" prop="saleCount"/>
      <el-table-column label="销售折损率" align="center" prop="saleLoss" :formatter="showSaleLossPercent"/>
      <el-table-column label="总折损率" align="center" prop="totalLoss" :formatter="showTotalLossPercent"/>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { storeLoss } from "@/api/dy/statistics";
import { queryProduct } from "@/api/dy/product";

export default {
  name: "Sale",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售单表格数据
      List: [],
      //
      productList: [],
      //
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: null,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getProductList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      storeLoss(this.queryParams).then(response => {
        this.List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询产品管理列表 */
    getProductList() {
      queryProduct().then(response => {
        this.productList = response.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    showOrderLossPercent(row) {
      return Math.floor(row.orderLoss * 100) + "%"
    },
    showProduceLossPercent(row) {
      return Math.floor(row.produceLoss * 100) + "%"
    },
    showSaleLossPercent(row) {
      return Math.floor(row.saleLoss * 100) + "%"
    },
    showTotalLossPercent(row) {
      return Math.floor(row.totalLoss * 100) + "%"
    },
  

  }
};
</script>
